<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<input type="text" class="p1" placeholder="用户名">
<input type="text" class="p2" placeholder="密码">    <br>
<button class="b1">登录</button>
<button class="b2">注册</button>
</body>
<script src="./axios.js"></script>
<script>
    var oIpt1=document.querySelector('.p1')
    var oIpt2=document.querySelector('.p2')
    var oBtn1=document.querySelector('.b1')
    var oBtn2=document.querySelector('.b2')
    oBtn1.onclick=function(){
    axios({
    method:'post',
    url:'http://localhost:8888/users/login',
    headers:{
        "content-type":"application/x-www-form-urlencoded"
    },
    data:{
        username:oIpt1.value,
        password:oIpt2.value
    }
}).then(function(res){
    console.log(res);
    if(res.data.code==1){
        location.href='商品.html'
    }
    if(res.data.code!=1)
        alert("用户名或密码错误")
})
    }
    oBtn2.onclick=function(){
        location.href='注册.html'
    }
</script>
</html>